home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
vol6n20.arc
/
FIGURES.ARC
/
FIGURE.4
< prev
next >
Wrap
Text File
|
1987-10-31
|
972b
|
41 lines
PROGRAM PowerOf2;
CONST
Power2 : array[0..15] of Integer =
(1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,$8000);
FUNCTION Power_2(I : integer) : integer;
VAR N : byte;
temp : Integer;
BEGIN
temp := 1;
FOR N := 2 to I DO temp := temp * 2;
Power_2 := temp;
END;
FUNCTION Power_2a(I : integer) : integer;
BEGIN
Power_2a := Power2[I];
END;
{$I timer.inc}
VAR I, J, K : integer;
CONST reps = 10000;
BEGIN
K := 15;
timer(on);
FOR I := 1 to reps DO J := Power_2(K);
timer(off);
Write('Power_2 took ',time:1:2);
WriteLn(' seconds for ',reps,' repetitions');
timer(on);
FOR I := 1 to reps DO J := Power_2a(K);
timer(off);
Write('Power_2a took ',time:1:2);
WriteLn(' seconds for ',reps,' repetitions');
timer(on);
FOR I := 1 to reps DO J := Power2[K];
timer(off);
Write('Power2 array took ',time:1:2);
WriteLn(' seconds for ',reps,' repetitions');
END.